 

import Model.*;

/**
 * Product Controller
 * @author Stefan
 */
public class ProductController {

    private static ProductController instance = new ProductController();
    ProductContainer container;

    private ProductController()
    {
        this.container = ProductContainer.getInstance();
    }
    
    /**
     * Singleton
     * @return instance of ProductController
     */
    public static ProductController getInstance()
    {
        return instance;
    }

    /**
     * Add new Product
     * @param id
     * @param name
     * @param description
     * @param price
     * @param rentalPrice
     * @param sale
     * @return true, if added successfully
     */
    public boolean addProduct(String id, String name, String description, double price, double rentalPrice, double sale, int minStock)
    {
        boolean added = false;
        if (container.findProduct(id) == null)
        {
            Product product = new Product(id, name, description, price, rentalPrice, sale, minStock);
            added = container.addProduct(product);
        }
        return added;
    }

    /**
     * Find Product by ID
     * @param ID
     * @return Product
     */
    public Product findProduct(String ID)
    {
        return container.findProduct(ID);
    }

    /**
     * Delete Product by name
     * @param name
     * @return true, if added successfully
     */
    public boolean deleteProduct(String name)
    {
        boolean deleted = false;
        Product product = findProduct(name);
        if (product != null)
        {
            container.deleteProduct(product);
            deleted = true;
        }
        return deleted;
    }

    /**
     * Check if Product with given ID exists
     * @param ID
     * @return true if ID exists
     */
    public boolean checkExistingID(String ID)
    {
        boolean exist = true;
        if (container.findProduct(ID) == null)
        {
            exist = false;
        }
        return exist;
    }
}
